<?php

namespace app\admin\controller\refund;

use app\common\controller\Backend;

use think\Controller;
use think\Request;

/**
 * 收费退款单
 *
 * @icon fa fa-circle-o
 */
class Index extends Backend
{
    
    /**
     * Refund模型对象
     */
    protected $model = null;
    protected $expensesModel = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('Refund');
        $this->expensesModel = model('expenses');
        $this->view->assign('expenses',$this->expensesModel->field('id,project_code,house_code,community_code')->select());
    }

    public function index(){
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('pkey_name')) {
                return $this->selectpage();
            }

            list($where, $sort, $order, $offset, $limit, $orderParams) = $this->buildparams();
            $total = $this->model->where($where)->count();
            $list = $this->model->with(['expenses' => ['community','house','project']])->where($where)->order($orderParams)->limit($offset, $limit)->select();
            $result = array("total" => $total, "rows" => $list);
            return json($result);
        }
        return $this->view->fetch();
    }

    public function add()
    {
        return parent::create('form');
    }

    public function edit($ids = NULL)
    {
        return parent::modify($ids,'form');
    }

    public function del($ids = null){
        $where = array(
            'id' => array('in',$ids)
        );
        parent::delete($where);
    }
}
